// @ts-check
import { fetch, post } from '../../utils/requests.js'
// @ts-ignore

/**
 * 获取图形验证码
 * @description 获取图形验证码
 * @param { { rand: string } } data 随机码
 * @returns {Promise<{ code: string, message: string, data: string }>} 返回值：base64的图片
 */
const getCaptcha = function (data) {
  const url = '/api/common/captcha'
  return fetch(url, data)
}

/**
 * 登录
 * @param { { username: string, password: string, captcha: string, rand: string } } data 账号、密码、随机数和验证码
 * @returns {Promise<{ code: string, message: string, data: { org_id: string, org_name: string, org_type: string }[] }>} 返回值：成员所在的组织信息
 */
const login = function (data) {
  const url = '/api/service_provider_staff/verify'
  return post(url, data, {}, false)
}

/**
 * 获取用户信息
 * @description 获取用户信息
 * @param { { rand: string } } data
 * @returns {Promise<{ code: string, message: string, data: string }>}
 */
const getInfo = function (data, query) {
  const url = '/data/service_provider'
  return fetch(url, data, {}, true, false, query)
}

export {
  getCaptcha,
  login,
  getInfo
}
